<template>
	<view class="login-css">
		<view class="oldPwd">
			<text>原密码：</text>
			<input class="input-value" placeholder="请输入原密码" password v-model="oldss" />
		</view>
		<view class="oldPwd">
			<text>新密码：</text>
			<input class="input-value" placeholder="请输入新密码" password v-model="oldPw" />
		</view>
		<view class="oldPwd">
			<text>确认新密码：</text>
			<input class="input-value" placeholder="请再次输入新密码" password v-model="newPwd" />
		</view>
		<button @click="submits" class="login-btn">确认修改</button>
	</view>
</template>

<script>
	import {
		checkPwdRe,
		checkNull
	} from "@/common/common.js"
	export default {
		data() {
			return {
				oldss: '',
				oldPw: '',
				newPwd: ''
			}
		},
		methods: {
			submits() {
				if (!checkNull(this.oldss)) {
					return
				}
				if (!checkPwdRe(this.oldPw, this.newPwd)) {
					return
				}

				uni.showModal({
					title: '提示',
					content: '确定修改密码吗？',
					success: (res) => {
						if (res.confirm) {
							uni.showLoading({
								title: "提交中...",
							})
							uni.request({
								url: "http://114.215.179.225:9001/yg-account/api/smallProgram/updatePassWord",
								method: "POST",
								data: {
									oldPassWord: this.oldss,
									newPassWord: this.oldPw,
								},
								complete() {
									setTimeout(() => {
										uni.hideLoading()
									}, 500)
								},
								success: (res) => {
									let resData = res.data
									
									uni.showToast({
										title: resData.uiMsg,
										icon: "none",
									});

									if (resData.code === 200 && resData.success) {
										this.goLogin()
									} else if (resData.code === 401) {
										this.goLogin()
									}
								}
							})
						}
					}
				});
			},
			goLogin() {
				uni.clearStorageSync('userInfo')
				uni.reLaunch({
					url: '../login/login'
				});
			},
		}
	}
</script>

<style scoped lang="scss">
	.login-css {
		width: 100%;
		// height: 100vh;
		display: flex;
		flex-direction: column;
		align-items: center;
		position: relative;
		box-sizing: border-box;
		padding-top: 70upx;

		.oldPwd {
			width: 690upx;
			height: 100upx;
			background: #F9F9FB;
			opacity: 1;
			border-radius: 16upx;
			display: flex;
			padding-left: 30upx;
			font-size: 28upx;
			font-family: PingFang SC;
			font-weight: bold;
			line-height: 40upx;
			color: #333333;
			opacity: 0.9;
			margin-bottom: 88upx;
			justify-content: flex-start;
			align-items: center;

			text {
				// width: 112upx;
				height: 40upx;

			}

			input {
				// width: 548upx;
				height: 100%;
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #999999;
			}

		}

		.login-btn {
			width: 640upx;
			// position: absolute;
			// bottom: 508upx;
			height: 96upx;
			background: #2573B0;
			opacity: 1;
			border-radius: 48upx;
			font-size: 32upx;
			font-family: PingFang SC;
			font-weight: bold;
			line-height: 96upx;
			color: #FFFFFF;
		}
	}
</style>
